<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="imId，通讯用" prop="imId">-->
<!--        <el-input-->
<!--          v-model="queryParams.imId"-->
<!--          placeholder="请输入imId，通讯用"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="头像地址" prop="logoImg">-->
<!--        <el-input-->
<!--          v-model="queryParams.logoImg"-->
<!--          placeholder="请输入头像地址"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="累计订单数量，默认为0" prop="orderCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.orderCount"-->
<!--          placeholder="请输入累计订单数量，默认为0"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="积分" prop="points">-->
<!--        <el-input-->
<!--          v-model="queryParams.points"-->
<!--          placeholder="请输入积分"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="用户中心用户id，使用 BIGINT 类型" prop="uid">-->
<!--        <el-input-->
<!--          v-model="queryParams.uid"-->
<!--          placeholder="请输入用户中心用户id，使用 BIGINT 类型"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="性别(1男 2女 3其他)" prop="gender">-->
<!--        <el-select v-model="queryParams.gender" placeholder="请选择性别(1男 2女 3其他)" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.sys_user_sex"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="出生日期" prop="birthDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.birthDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择出生日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item label="身份证" prop="idCardNumber">
        <el-input
          v-model="queryParams.idCardNumber"
          placeholder="请输入身份证号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="婚姻状况('1已婚','2未婚','3离婚','4丧偶')" prop="maritalStatus">-->
<!--        <el-select v-model="queryParams.maritalStatus" placeholder="请选择婚姻状况('1已婚','2未婚','3离婚','4丧偶')" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.patient_sys_marriage"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="电子邮件" prop="email">-->
<!--        <el-input-->
<!--          v-model="queryParams.email"-->
<!--          placeholder="请输入电子邮件"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="创建人" prop="createUser">-->
<!--        <el-input-->
<!--          v-model="queryParams.createUser"-->
<!--          placeholder="请输入创建人"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="更新人" prop="updateUser">-->
<!--        <el-input-->
<!--          v-model="queryParams.updateUser"-->
<!--          placeholder="请输入更新人"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['patientInfo:patientInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['patientInfo:patientInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['patientInfo:patientInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['patientInfo:patientInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="patientInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="患者唯一标识" align="center" prop="id" />
      <el-table-column label="imId，通讯用" align="center" prop="imId" />
      <el-table-column label="头像地址" align="center" prop="logoImg" />
      <el-table-column label="累计订单数量，默认为0" align="center" prop="orderCount" />
      <el-table-column label="积分" align="center" prop="points" />
      <el-table-column label="用户中心用户id，使用 BIGINT 类型" align="center" prop="uid" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别(1男 2女 3其他)" align="center" prop="gender">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.gender"/>
        </template>
      </el-table-column>
      <el-table-column label="出生日期" align="center" prop="birthDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="身份证号码" align="center" prop="idCardNumber" />
      <el-table-column label="婚姻状况('1已婚','2未婚','3离婚','4丧偶')" align="center" prop="maritalStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.patient_sys_marriage" :value="scope.row.maritalStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="电子邮件" align="center" prop="email" />
      <el-table-column label="通讯地址" align="center" prop="address" />
      <el-table-column label="创建人" align="center" prop="createUser" />
      <el-table-column label="更新人" align="center" prop="updateUser" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['patientInfo:patientInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['patientInfo:patientInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改patientInfo对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="imId，通讯用" prop="imId">
          <el-input v-model="form.imId" placeholder="请输入imId，通讯用" />
        </el-form-item>
        <el-form-item label="头像地址" prop="logoImg">
          <el-input v-model="form.logoImg" placeholder="请输入头像地址" />
        </el-form-item>
        <el-form-item label="累计订单数量，默认为0" prop="orderCount">
          <el-input v-model="form.orderCount" placeholder="请输入累计订单数量，默认为0" />
        </el-form-item>
        <el-form-item label="积分" prop="points">
          <el-input v-model="form.points" placeholder="请输入积分" />
        </el-form-item>
        <el-form-item label="用户中心用户id，使用 BIGINT 类型" prop="uid">
          <el-input v-model="form.uid" placeholder="请输入用户中心用户id，使用 BIGINT 类型" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别(1男 2女 3其他)" prop="gender">
          <el-select v-model="form.gender" placeholder="请选择性别(1男 2女 3其他)">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出生日期" prop="birthDate">
          <el-date-picker clearable
            v-model="form.birthDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="身份证号码" prop="idCardNumber">
          <el-input v-model="form.idCardNumber" placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item label="婚姻状况('1已婚','2未婚','3离婚','4丧偶')" prop="maritalStatus">
          <el-select v-model="form.maritalStatus" placeholder="请选择婚姻状况('1已婚','2未婚','3离婚','4丧偶')">
            <el-option
              v-for="dict in dict.type.patient_sys_marriage"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="电子邮件" prop="email">
          <el-input v-model="form.email" placeholder="请输入电子邮件" />
        </el-form-item>
        <el-form-item label="通讯地址" prop="address">
          <el-input v-model="form.address" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="创建人" prop="createUser">
          <el-input v-model="form.createUser" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="更新人" prop="updateUser">
          <el-input v-model="form.updateUser" placeholder="请输入更新人" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPatientInfo, getPatientInfo, delPatientInfo, addPatientInfo, updatePatientInfo } from "@/api/patient/patientInfo";

export default {
  name: "PatientInfo",
  dicts: ['patient_sys_marriage', 'sys_user_sex'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // patientInfo表格数据
      patientInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        imId: null,
        logoImg: null,
        orderCount: null,
        points: null,
        uid: null,
        name: null,
        gender: null,
        birthDate: null,
        idCardNumber: null,
        maritalStatus: null,
        phone: null,
        email: null,
        address: null,
        createUser: null,
        updateUser: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        gender: [
          { required: true, message: "性别(1男 2女 3其他)不能为空", trigger: "change" }
        ],
        birthDate: [
          { required: true, message: "出生日期不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询patientInfo列表 */
    getList() {
      this.loading = true;
      listPatientInfo(this.queryParams).then(response => {
        this.patientInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        imId: null,
        logoImg: null,
        orderCount: null,
        points: null,
        uid: null,
        name: null,
        gender: null,
        birthDate: null,
        idCardNumber: null,
        maritalStatus: null,
        phone: null,
        email: null,
        address: null,
        createTime: null,
        updateTime: null,
        createUser: null,
        updateUser: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加patientInfo";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPatientInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改patientInfo";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePatientInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPatientInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除patientInfo编号为"' + ids + '"的数据项？').then(function() {
        return delPatientInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('patientInfo/patientInfo/export', {
        ...this.queryParams
      }, `patientInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
